package com.lagou.tp.filter;

import com.lagou.tp.util.TpMapUtil;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

/**
 * @AUTHOR: yb.feng
 * @DATE: 2020/6/15 22:14
 * @DESC:
 */
@Activate(group = {CommonConstants.PROVIDER})
public class TPMonitorFilter implements Filter {


    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        Long start = System.currentTimeMillis();
        Result result = invoker.invoke(invocation);
        Long cost = System.currentTimeMillis() - start;
        String methodName = invocation.getMethodName();
        TpMapUtil.addCost(methodName, cost);
        return result;
    }

}
